<?php

/**
 * 文件由尚数增量代码引擎生成
 * @author: Shann 851188611@qq.com
 */

namespace app\admin\controller;

class OrderBase
{
    public function index()
    {
        $orders = \app\model\Order::field(['id', 'code', 'status_value', 'payable_amount', 'paid_amount', 'created_at', 'updated_at']);

        $orders->order('id', 'eq');

        $data['orders'] = $orders->select();

        return json(['code' => 20000, 'data' => $data]);
    }

    public function detail()
    {
        $order = \app\model\Order::field(['id', 'code', 'status_value', 'payable_amount', 'paid_amount', 'created_at', 'updated_at']);

        $order->where('id', input('id'));

        $order->with(['orderProducts' => function ($query) {
            $query->field(['id', 'order_id', 'product_name', 'product_price', 'quantity']);
        }]);

        $order->with(['payments' => function ($query) {
            $query->field(['id', 'order_id', 'code', 'amount', 'status_value']);
        }]);

        $data['order'] = $order->find();

        return json(['code' => 20000, 'data' => $data]);
    }
}
